Skip to content

fix(perps): stabilize Lighter account loading - #10119

Merged
abretonc7s merged 1 commit into
mainfrom
fix/perps/lighter-account-loading
Sep 8, 2026
Merged

fix(perps): stabilize Lighter account loading#10119
abretonc7s merged 1 commit into
mainfrom
fix/perps/lighter-account-loading

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Explanation

Lighter account discovery can return sparse balance fields, and API code 21100 authoritatively means the selected wallet has no venue account. The provider previously rejected funded accounts during discovery and left no-account subscribers waiting indefinitely.

This change validates only identity fields during address discovery, queries all API-key slots so non-default registrations are found, emits empty account state only for confirmed no-account responses, and preserves existing state for transport, auth, and integrity failures. REST trade decoding now permits an omitted counterparty PnL while the fill adapter still requires the selected account's PnL. It also removes the per-frame Lighter price debug log.

Validated with:

  • Full @metamask/perps-controller suite (89.48% line coverage) and full Core monorepo build
  • Focused Lighter service/adapter tests (109/109), targeted ESLint, Prettier, and package changelog validation
  • Mobile typecheck against yalc package 16.1.0 (yalc.sig 12ffef2527e5de1f35bb8b3cff91fa02)
  • iOS mm-1 no-account settlement on dev7: markets rendered with no balance, positions, orders, or activity
  • iOS funded Lighter testnet lifecycle on rebased Mobile 5beed0f35b using published mm-harness@0.47.1: BTC order 242458746910186, position 0.00012 at 81267.2, close 68943931413978, final state flat (26/26 recipe nodes)

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation for new or updated code as appropriate
  • I've communicated consumer-facing changes in the package changelog
  • I've introduced breaking changes — not applicable; this change is non-breaking

Note

Medium Risk
Changes Lighter account-binding, empty-state emission, and API-key discovery paths that affect trading readiness and live subscriptions; behavior is narrowed with tests but mistakes could show wrong balances or block registration.

Overview
Fixes Lighter account discovery and subscriber settlement so wallets with funded venue accounts are not rejected on sparse discovery payloads, and UI no longer spins forever when the wallet truly has no Lighter account.

Account resolution: accountsByL1Address now validates only identity fields (AccountSummaryStruct / LighterAccountSummary), while full account reads stay strict. API code 21100 and empty subAccounts map to LighterAccountNotFoundError. On channel setup, that case emits authoritative empty account/positions/orders; transport, auth, capability, and malformed responses keep the last snapshot.

Trading readiness: Venue key checks call getApiKeys(accountIndex) (all slots) instead of probing a single unused slot, which previously returned api key not found and blocked first-time registration.

History / noise: REST trade decoding allows omitted askAccountPnl / bidAccountPnl; the fill adapter still requires PnL for the selected account. Per-frame Lighter price-stream debug logging is removed.

Reviewed by Cursor Bugbot for commit dcf7cc6. Bugbot is set up for automated code reviews on this repo. Configure here.

@abretonc7s
abretonc7s force-pushed the fix/perps/lighter-account-loading branch from f84b740 to 7b91634 Compare September 4, 2026 15:50
@abretonc7s
abretonc7s marked this pull request as ready for review September 4, 2026 15:50
@abretonc7s
abretonc7s requested review from a team as code owners September 4, 2026 15:50
@abretonc7s
abretonc7s enabled auto-merge September 4, 2026 15:50
@abretonc7s abretonc7s added bug Something isn't working team-perps labels Sep 4, 2026
@abretonc7s
abretonc7s force-pushed the fix/perps/lighter-account-loading branch from 7b91634 to dcf7cc6 Compare September 4, 2026 16:27
@abretonc7s

Copy link
Copy Markdown
Contributor Author

Fresh Core → Mobile validation for dcf7cc65e:

  • Mobile's installed @metamask/perps-controller 16.1.0 dist/index.cjs is byte-identical to this Core build (SHA-256 f2622e70aadb52afc4ece5584faadc51d563139f46b7905ff3a572e743fa8827).
  • Android Pixel 6a (29071JEGR20638) completed a clean dev bundle and bridge verification, selected Lighter mainnet, and rendered a live BTC Lite chart with an observed price update. Android remained read-only.
  • iOS mm-1, fixture account Trading, selected Lighter testnet and completed one authorized BTC Lite market-order lifecycle: $10 notional, 2× leverage, Lighter placement receipt, independent live-position assertion, successful Lighter close receipt, then fresh assertions of zero matching BTC positions and zero open orders.
  • Mobile focused tests: 10 suites / 414 tests passed; Mobile TypeScript passed.
  • Core focused tests: 3 suites / 394 tests passed; Core TypeScript, changed-file lint/format, and perps-controller changelog validation passed.
  • No mainnet mutation or external funding occurred.

All current CI checks and Cursor Bugbot are passing; I found no actionable inline bot comments.

@abretonc7s
abretonc7s added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 3761095 Sep 8, 2026
46 checks passed
@abretonc7s
abretonc7s deleted the fix/perps/lighter-account-loading branch September 8, 2026 09:24
@abretonc7s abretonc7s mentioned this pull request Sep 9, 2026
4 tasks
pull Bot pushed a commit to Reality2byte/core that referenced this pull request Sep 9, 2026
## Explanation

Publishes `@metamask/perps-controller@16.2.0`. No other workspace
packages are version-bumped.

This is a minor, not a major. Expanding `PerpsErrorCode` with the
margin-mode codes is additive; clients should handle unknown codes in a
catch-all rather than an exhaustive map. Optional
`OrderParams.marginMode` and `MarketInfo.marginMode` keep existing
callers on the isolated-leverage path.

Also includes the HyperLiquid TWAP terminal-record fix and Lighter
account/market/log fixes.

## References

- MetaMask#10136
- MetaMask#10122
- MetaMask#10119
- MetaMask#10110

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> This PR only bumps versions and edits changelog/README/JSDoc; trading
behavior ships in the referenced feature PRs, not in this diff.
> 
> **Overview**
> Cuts **release 1245.0.0**, publishing
**`@metamask/perps-controller@16.2.0`** (monorepo root version bump
only; no other workspace packages change).
> 
> The diff is mostly release bookkeeping: **`package.json` versions**, a
new **`[16.2.0]` changelog** section (margin-mode error codes and
HyperLiquid `marginMode` API, TWAP terminal-record fix, Lighter
account/market/logging fixes — already merged via linked PRs), and
**consumer guidance** updates.
> 
> **Policy clarification:** new **`PerpsErrorCode` values (including the
four margin-mode codes) are documented as additive minors**, not
breaking — the changelog drops the prior **BREAKING** wording.
**`README.md`** adds an **Error codes** section and
**`perpsErrorCodes.ts`** JSDoc now tells clients to use a **catch-all**
for unknown codes instead of an exhaustive `Record<PerpsErrorCode, …>`.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
add8f2d. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working team-perps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants